package database;

import java.util.ArrayList;

import metier.Lame;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ArrayAdapter;

public class LameDatabase {

	private HoraceDatabase hdb;
	private SQLiteDatabase db;
	private static final String TABLE = "lames";
	private static final String COL_LAME_LIBELLE = "libelle";
	private static final String COL_LAME_LONGUEUR = "longueur";
	private static final String COL_LAME_LARGEUR = "largeur";

	public LameDatabase(Context context){
		hdb = new HoraceDatabase(context, "castoracema", null, 1);
	}

	public long insertLame(Lame l){
		db = hdb.getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put(COL_LAME_LARGEUR, l.getLargeur());
		values.put(COL_LAME_LONGUEUR, l.getLongueur());
		values.put(COL_LAME_LIBELLE, l.getLibelle());
		return db.insert(TABLE, null, values);
	}

	public ArrayList<Lame> getAllLames(){
		db = hdb.getReadableDatabase();
		ArrayList<Lame> lames = new ArrayList<Lame>();
		Cursor cr = db.query(TABLE, new String[]{COL_LAME_LIBELLE, COL_LAME_LONGUEUR, COL_LAME_LARGEUR}, null, null, null, null, null);
		while(cr.moveToNext()){
			lames.add(new Lame(cr.getString(0), Float.valueOf(cr.getString(1)), Float.valueOf(cr.getString(2))));
		}
		return lames;
	}

}
